#include <stdio.h>

int main_26()
{
    int prev,cur,mul=1,res=0;
    scanf("%d",&prev);
    res+=prev;
    if (0==prev)
    {
        printf("%d\n",res);
        return 0;
    }else
    {
        scanf("%d",&cur);
        while (cur)
        {
            if (cur==1)
            {
                res+=1;
                mul=1;
            }else
            {
                if (1==prev)
                {
                    res+=2;
                    mul=1;
                }
                else
                {
                    res+=++mul*2;
                }
            }
            prev=cur;
            scanf("%d",&cur);
        }
    }
    printf("%d\n",res);
    return 0;
}
